package code.main.controller.hall
{
	import code.app.AppCtrlList;
	import code.app.AppDmList;
	import code.app.AppView;
	import code.main.controller.event.EventManager;
	import code.main.controller.event.EventName;
	import code.main.controller.event.MyEvent;
	import code.main.modle.table.Player;
	import code.main.view.hall.NavView;
	import code.main.view.hall.TopInfoView;
	
	import com.yy.tools.string.StringUtil;
	
	import flash.events.Event;
	import flash.text.TextField;

	public class TopInfoCtrl
	{
		private var _topInfoView:TopInfoView;
		private var _navView:NavView;
		public function TopInfoCtrl()
		{
		}
		
		public function start():void {
			_topInfoView = new TopInfoView();
			AppView.getInstance().topInfoLayer.addChild(_topInfoView);
			_navView = new NavView();
			AppView.getInstance().topInfoLayer.addChild(_navView);
			gameMoneyChangeFunc(null);
			platfromMoneyChangeFunc(null);
			levelChangeFunc(null);
			expChangeFunc(null);
			addEvent();
		}
		
		private function addEvent():void {
			EventManager.getInstance().addEventListener(EventName.GAME_MONEY_CHANGE, gameMoneyChangeFunc);
			EventManager.getInstance().addEventListener(EventName.PLATFORM_MONEY_CHANGE, platfromMoneyChangeFunc);
			EventManager.getInstance().addEventListener(EventName.LEVEL_CHANGE, levelChangeFunc);
			EventManager.getInstance().addEventListener(EventName.EXP_CHANGE, expChangeFunc);
			EventManager.getInstance().addEventListener(EventName.ENTER_HALL, enterHallFunc);
			EventManager.getInstance().addEventListener(EventName.ENTER_TABLE, enterTableFunc);
		}
		
		/**
		 *进入大厅 
		 * 
		 */
		private function enterHallFunc(e:Event):void {
			_navView.visible = true;
		}
		
		/**
		 *进入房间 
		 * 
		 */
		private function enterTableFunc(e:Event):void {
			_navView.visible = false;
		}
		
		/**
		 *游戏币变化 
		 * @param e
		 * 
		 */
		private function gameMoneyChangeFunc(e:MyEvent):void {
			var value:int = AppDmList.getInstance().player.gameMoney;
			_topInfoView.gameMoney = value;
		}
		
		/**
		 *中介币变化 
		 * @param e
		 * 
		 */
		private function platfromMoneyChangeFunc(e:MyEvent):void {
			var value:int = AppDmList.getInstance().player.platformMoney;
			_topInfoView.platfromMoney = value;
		}
		
		/**
		 *等级变化 
		 * @param e
		 * 
		 */
		private function levelChangeFunc(e:MyEvent):void {
			var value:int = AppDmList.getInstance().player.level;
			_topInfoView.level = value;
		}
		
		/**
		 *经验变化 
		 * @param e
		 * 
		 */
		private function expChangeFunc(e:MyEvent):void {
			var p:Player = AppDmList.getInstance().player;
			_topInfoView.setExperience(p.exp, AppDmList.getInstance().levelDm.getNeedExp(p.level));
		}
	}
}